package com.njtoyo.taxi.admin.rest.controller.data;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.njtoyo.taxi.admin.aop.PassToken;
import com.njtoyo.taxi.admin.aop.PermissionScope;
import com.njtoyo.taxi.admin.mapper.secondary.entity.data.DashboardCallDailyInfo;
import com.njtoyo.taxi.admin.rest.presenter.data.funnel.OrderCallChartVO;
import com.njtoyo.taxi.admin.rest.presenter.data.funnel.TodayStatisticVO;
import com.njtoyo.taxi.admin.rest.presenter.finance.FinanceAllowanceStatsPresenter;
import com.njtoyo.taxi.admin.rest.wrapper.data.funnel.FunnelWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.finance.FinanceStatWrapper;
import com.njtoyo.taxi.admin.service.data.FunnelService;
import com.njtoyo.taxi.entity.backend.AdminUser;
import com.taxi.entity.common.RestResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * 漏斗页面接口
 */
@RequestMapping("/data/funnel")
@RestController
public class FunnelController {


    @Autowired
    FunnelService funnelService;


    /**
     * 今日数据统计
     *
     * @return
     */
    @GetMapping("/todayStatistic")
    public RestResult<TodayStatisticVO> todayStatistic(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser, FunnelWrapper funnelWrapper) {
        return funnelService.todayStatistic(adminUser, funnelWrapper);
    }


    /**
     * 订单趋势图
     *
     * @param adminUser
     * @param funnelWrapper
     * @return
     */
    @GetMapping("/order-chart/{type}")
    public RestResult<?> orderChart(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser, @PathVariable Integer type, FunnelWrapper funnelWrapper) {
        return funnelService.orderChart(adminUser, type, funnelWrapper);
    }

    @GetMapping("/no-reply/list")
    @PassToken
    public RestResult<?> getNoReplyList(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser, FunnelWrapper funnelWrapper) {
        return funnelService.getNoReplyList(adminUser, funnelWrapper);
    }

    @GetMapping("/cancel/list")
    @PassToken
    public RestResult<?> getCancelList(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser, FunnelWrapper funnelWrapper) {
        return funnelService.getCancelList(adminUser, funnelWrapper);
    }


    @GetMapping("/order-grab-chart")
    public RestResult<?> get30DayGrabOrder(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser, FunnelWrapper funnelWrapper) {
        return funnelService.get30DayGrabOrder(adminUser, funnelWrapper);
    }


    /**
     * 订单数据
     *
     * @param adminUser
     * @param funnelWrapper
     * @return
     */
    @GetMapping("/order-data")
    public RestResult<?> getOrderData(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser, FunnelWrapper funnelWrapper) {
        return funnelService.getOrderData(adminUser, funnelWrapper);
    }

    /**
     * 运力数据
     *
     * @param adminUser
     * @param funnelWrapper
     * @return
     */
    @GetMapping("/capacity-data")
    public RestResult<?> getCapacityData(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser, FunnelWrapper funnelWrapper) {
        verifyForm(funnelWrapper);
        return funnelService.getCapacityData(adminUser, funnelWrapper);
    }


    @GetMapping("/getSendDrivers")
    @PassToken
    public RestResult<?> getSendDrivers(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser, FunnelWrapper funnelWrapper) {
        return funnelService.getSendDrivers(adminUser, funnelWrapper);
    }

    @GetMapping("/getGrabDrivers")
    @PassToken
    public RestResult<?> getGrabDrivers(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser, FunnelWrapper funnelWrapper) {
        return funnelService.getGrabDrivers(adminUser, funnelWrapper);
    }

    private void verifyForm(FunnelWrapper funnelWrapper) {
        funnelWrapper.setStartDate(DateUtil.beginOfDay(DateUtil.date()));
        funnelWrapper.setEndDate(DateUtil.endOfDay(DateUtil.date()));
    }




}
